<template>
	<view class="mainbgc">
		<view class="mainpadding paddingbottom">
			<view class="ffffff radius mainpadding  margin_top" v-for="item in  dizhilist" :key="item.id"
				@click="checkaddress(item.id)">
				<view class="flexleft">
					<view class="titletext margin_right2">{{item.name}}</view>
					<view class="titletext">{{item.mobile}}</view>
				</view>
				<view class="flexleft xiahuaxian margin_top">
					<view class="dizhi margin_right1"></view>
					<view class="nostrongtext">{{item.cityinfo}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="flexleft" @click.stop="selectmr(item.id)">
						<!-- 已勾选 -->
						<view class="yigouxuan margin_right1" v-if="item.status==0"></view>
						<!-- 未勾选 -->
						<view class="weigouxuan margin_right1" v-if="item.status==1"></view>
						<view class="nostrongtext">设为默认</view>
					</view>
					<view class="flexright">
						<view class="flexleft margin_right4" @click.stop="bianji(item.id)">
							<view class="bianji margin_right1"></view>
							<view class="nostrongtext">编辑</view>
						</view>
						<view class="flexleft" @click.stop="deletes(item.id)">
							<view class="del margin_right1"></view>
							<view class="nostrongtext">删除</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 固定底部 -->
		<view class="gudingdb" @click="Added">
			<view class="bigbtn">+新增收货地址</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				dizhilist: {},
				type: ""
			}
		},
		onLoad(options) {
			this.type = options.type
		},
		onShow() {
			this.getdzlist();
		},
		methods: {
			checkaddress(id){
				if(this.type==1){
					uni.$emit("addressId",id)
					uni.navigateBack(1)
				}
			},
			getdzlist() { //地址列表
				httpRequest.request('/api/user/addressList', 'GET', {}).then(res => {
					this.dizhilist = res.data
				})
			},
			selectmr(id) { //地址设置默认
				httpRequest.request('/api/user/setAddressMr', 'GET', {
					id: id,
					status: 1,
				}, false, false, true).then(res => {
					uni.hideLoading() //隐藏loading显示框
					if (res.code == 1) {
						httpRequest.toast(res.msg) //弹框显示设置成功
						this.getdzlist();
					} else {
						httpRequest.toast(res.msg)
					}
				})
			},
			//删除接口
			deletes(id) {
				httpRequest.modal('提示', '确认删除当前数据吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/user/deladdress', 'GET', {
							id: id
						}, false, false, true).then(res => {
							if (res.code == 1) {
								httpRequest.toast(res.msg)
								this.getdzlist();
							} else {
								httpRequest.toast(res.msg)
							}
						})
					}
				})
			},
			bianji(id) { //编辑跳转
				uni.navigateTo({
					url: '../../pages/shopping/tianjiashdz?id=' + id
				})
			},
			Added() { //添加收货人
				uni.navigateTo({
					url: '../../pages/shopping/tianjiashdz'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.gudingdb {
		background-color: #fff;
	}

	.kym {
		margin: 250rpx auto 0;
		width: 319rpx;
		height: 267rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.weigouxuan {
		width: 22rpx;
		border-radius: 50%;
		height: 22rpx;
		border: 1rpx solid #999999;
	}

	.yigouxuan {
		width: 24rpx;
		height: 24rpx;
	}

	.xiahuaxian {
		padding-bottom: 30rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, .1);
	}

	.dizhi {
		width: 26rpx;
		height: 31rpx;
		background-size: 100% 100%;
		background-image: url('@/static/images/system/blue_dingwie.png');
	}
</style>
